/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainMenu.java
 *
 * Created on Sep 8, 2010, 5:38:14 PM
 */
package project.jpdftools.ui;

import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.File;
import java.util.ArrayList;
import java.util.logging.Level;
import javax.swing.*;
import project.jpdftools.constants.Const;
import project.jpdftools.documentinfo.ui.DocumentInfoUI;
import project.jpdftools.feedback.ui.FeedBackUI;
import project.jpdftools.headerfooter.ui.HeaderFooterUI;
import project.jpdftools.imagemerger.ImageMergerUI;
import project.jpdftools.managers.LocalizationManager;
import project.jpdftools.managers.LoggerManager;
import project.jpdftools.pagesetup.ui.PageSetupUI;
import project.jpdftools.pdfconverter.ui.PDFConverterUI;
import project.jpdftools.pdfmerger.PDFMergerUI;
import project.jpdftools.pdfsplitter.SplitterUI;
import project.jpdftools.ui.actionlisteners.ExportAction;
import project.jpdftools.ui.logic.JPDF;
import project.jpdftools.ui.logic.JPDFText;
import project.jpdftools.ui.managers.IconManager;
import project.jpdftools.ui.managers.ThemeManager;

/**
 *
 * @author Mido
 */
public class MainMenu extends javax.swing.JFrame {

    private static MainMenu main_menu_instance;
    ArrayList<JPDF> jpdf_data = new ArrayList<JPDF>(10);

    /**
     * Creates new form MainMenu
     */
    private MainMenu() {
        initComponents();
        // get the screen resolution
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        this.setSize(screen.width, screen.height - 40);

        // add action listeners
        bt_export_pdf.addActionListener(new ExportAction());

        // initialize localization UI components
        LocalizationManager localization_manager = new LocalizationManager(m_language);
        localization_manager.applyLocaliztionInUI();

        // initialize theme UI components
        ThemeManager theme_manager = new ThemeManager(m_themes);
        theme_manager.applyThemeInUI();

        // initialize icons UI components
        IconManager icon_manager = new IconManager(m_icons);
        icon_manager.applyIconsInUI();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tb_toolbar = new javax.swing.JToolBar();
        bt_new_pdf = new javax.swing.JButton();
        bt_load_file = new javax.swing.JButton();
        bt_save_file = new javax.swing.JButton();
        s_toolbar = new javax.swing.JToolBar.Separator();
        bt_merge_files = new javax.swing.JButton();
        bt_merge_images = new javax.swing.JButton();
        bt_split_file = new javax.swing.JButton();
        bt_convert = new javax.swing.JButton();
        sp_split_pane = new javax.swing.JSplitPane();
        scp_right = new javax.swing.JScrollPane();
        p_right = new javax.swing.JPanel();
        scp_left = new javax.swing.JScrollPane();
        tb_side_toolbar = new javax.swing.JToolBar();
        p_sidebar = new javax.swing.JPanel();
        bt_export_pdf = new javax.swing.JButton();
        bt_add_image = new javax.swing.JButton();
        bt_add_table = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        bt_add_text = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        m_file = new javax.swing.JMenu();
        mi_documnet_properties = new javax.swing.JMenuItem();
        mi_file_page_setup = new javax.swing.JMenuItem();
        s_file_menu = new javax.swing.JPopupMenu.Separator();
        mi_exit = new javax.swing.JMenuItem();
        m_add = new javax.swing.JMenu();
        mi_add_text = new javax.swing.JMenuItem();
        mi_add_table = new javax.swing.JMenuItem();
        mi_add_image = new javax.swing.JMenuItem();
        s_add_menu = new javax.swing.JPopupMenu.Separator();
        mi_add_header_footer = new javax.swing.JMenuItem();
        m_options = new javax.swing.JMenu();
        cbmi_show_icon_text = new javax.swing.JCheckBoxMenuItem();
        m_icons = new javax.swing.JMenu();
        m_themes = new javax.swing.JMenu();
        m_language = new javax.swing.JMenu();
        m_advanced = new javax.swing.JMenu();
        mi_free_unused_memory = new javax.swing.JMenuItem();
        mi_open_logger = new javax.swing.JMenuItem();
        m_help = new javax.swing.JMenu();
        mi_feedback = new javax.swing.JMenuItem();
        mi_what_is_new = new javax.swing.JMenuItem();
        mi_about = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle(Const.program_version);
        setIconImage(Toolkit.getDefaultToolkit().getImage("Data/Icons/Soft Scraps Icons/10.png"));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                MainMenu.this.windowClosing(evt);
            }
        });

        tb_toolbar.setFloatable(false);

        bt_new_pdf.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_NEW_FILE"));
        bt_new_pdf.setToolTipText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_TOOLTIP_NEW_FILE"));
        bt_new_pdf.setFocusable(false);
        bt_new_pdf.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bt_new_pdf.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bt_new_pdf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_new_pdfActionPerformed(evt);
            }
        });
        tb_toolbar.add(bt_new_pdf);

        bt_load_file.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_LOAD_FILE"));
        bt_load_file.setToolTipText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_TOOLTIP_LOAD_FILE"));
        bt_load_file.setFocusable(false);
        bt_load_file.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bt_load_file.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        tb_toolbar.add(bt_load_file);

        bt_save_file.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_SAVE"));
        bt_save_file.setToolTipText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_TOOLTIP_SAVE"));
        bt_save_file.setFocusable(false);
        bt_save_file.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bt_save_file.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        tb_toolbar.add(bt_save_file);
        tb_toolbar.add(s_toolbar);

        bt_merge_files.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_MERGE_FILES"));
        bt_merge_files.setToolTipText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_TOOLTIP_MERGE_FILES"));
        bt_merge_files.setFocusable(false);
        bt_merge_files.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bt_merge_files.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bt_merge_files.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_merge_filesActionPerformed(evt);
            }
        });
        tb_toolbar.add(bt_merge_files);

        bt_merge_images.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_MERGE_IMAGE_FILES"));
        bt_merge_images.setToolTipText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_TOOLTIP_MERGE_IMAGES"));
        bt_merge_images.setFocusable(false);
        bt_merge_images.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bt_merge_images.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bt_merge_images.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_merge_imagesActionPerformed(evt);
            }
        });
        tb_toolbar.add(bt_merge_images);

        bt_split_file.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_SPLIT"));
        bt_split_file.setToolTipText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_TOOLTIP_SPLIT"));
        bt_split_file.setFocusable(false);
        bt_split_file.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bt_split_file.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bt_split_file.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_split_fileActionPerformed(evt);
            }
        });
        tb_toolbar.add(bt_split_file);

        bt_convert.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_CONVERT"));
        bt_convert.setToolTipText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_TOOLTIP_CONVERT"));
        bt_convert.setFocusable(false);
        bt_convert.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bt_convert.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bt_convert.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_convertActionPerformed(evt);
            }
        });
        tb_toolbar.add(bt_convert);

        sp_split_pane.setDividerLocation(115);

        javax.swing.GroupLayout p_rightLayout = new javax.swing.GroupLayout(p_right);
        p_right.setLayout(p_rightLayout);
        p_rightLayout.setHorizontalGroup(
            p_rightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 731, Short.MAX_VALUE)
        );
        p_rightLayout.setVerticalGroup(
            p_rightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 484, Short.MAX_VALUE)
        );

        scp_right.setViewportView(p_right);
        p_right.setLayout(new javax.swing.BoxLayout(p_right, javax.swing.BoxLayout.Y_AXIS));

        sp_split_pane.setRightComponent(scp_right);

        tb_side_toolbar.setFloatable(false);
        tb_side_toolbar.setOrientation(JToolBar.VERTICAL);
        tb_side_toolbar.setMaximumSize(new java.awt.Dimension(85, 32767));

        p_sidebar.setMaximumSize(new java.awt.Dimension(108, 366));
        p_sidebar.setMinimumSize(new java.awt.Dimension(108, 366));

        bt_export_pdf.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_EXPORT_PDF"));
        bt_export_pdf.setToolTipText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_EXPORT_PDF_TOOLTIP"));
        bt_export_pdf.setFocusable(false);
        bt_export_pdf.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bt_export_pdf.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        bt_add_image.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_ADD_IMAGE"));
        bt_add_image.setToolTipText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_ADD_IMAGE_TOOLTIP"));
        bt_add_image.setFocusable(false);
        bt_add_image.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bt_add_image.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bt_add_image.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_add_imageActionPerformed(evt);
            }
        });

        bt_add_table.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_ADD_TABLE"));
        bt_add_table.setToolTipText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_ADD_TABLE_TOOLTIP"));
        bt_add_table.setFocusable(false);
        bt_add_table.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bt_add_table.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bt_add_table.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_add_tableActionPerformed(evt);
            }
        });

        bt_add_text.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_ADD_TEXT"));
        bt_add_text.setToolTipText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_ADD_TEXT_TOOLTIP"));
        bt_add_text.setFocusable(false);
        bt_add_text.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_add_textActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout p_sidebarLayout = new javax.swing.GroupLayout(p_sidebar);
        p_sidebar.setLayout(p_sidebarLayout);
        p_sidebarLayout.setHorizontalGroup(
            p_sidebarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_sidebarLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(p_sidebarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(bt_add_table, javax.swing.GroupLayout.PREFERRED_SIZE, 75, Short.MAX_VALUE)
                    .addComponent(bt_add_image, javax.swing.GroupLayout.PREFERRED_SIZE, 77, Short.MAX_VALUE)
                    .addComponent(bt_add_text, javax.swing.GroupLayout.PREFERRED_SIZE, 88, Short.MAX_VALUE)
                    .addComponent(bt_export_pdf, javax.swing.GroupLayout.PREFERRED_SIZE, 88, Short.MAX_VALUE)
                    .addComponent(jSeparator1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        p_sidebarLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {bt_add_image, bt_add_table, bt_add_text, bt_export_pdf});

        p_sidebarLayout.setVerticalGroup(
            p_sidebarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(p_sidebarLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(bt_add_text)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_add_table)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_add_image)
                .addGap(15, 15, 15)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_export_pdf)
                .addContainerGap(220, Short.MAX_VALUE))
        );

        p_sidebarLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {bt_add_image, bt_add_table, bt_add_text, bt_export_pdf});

        bt_add_text.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bt_add_text.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        tb_side_toolbar.add(p_sidebar);

        scp_left.setViewportView(tb_side_toolbar);

        sp_split_pane.setLeftComponent(scp_left);

        m_file.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_FILE"));

        mi_documnet_properties.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        mi_documnet_properties.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_DOCUMENT_INFO"));
        mi_documnet_properties.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mi_documnet_propertiesActionPerformed(evt);
            }
        });
        m_file.add(mi_documnet_properties);

        mi_file_page_setup.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        mi_file_page_setup.setText(LocalizationManager.getCurrent_resource().getString("PAGE_SETUP_PANEL_TITLE"));
        mi_file_page_setup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mi_file_page_setupActionPerformed(evt);
            }
        });
        m_file.add(mi_file_page_setup);
        m_file.add(s_file_menu);

        mi_exit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0));
        mi_exit.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_EXIT"));
        mi_exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mi_exitActionPerformed(evt);
            }
        });
        m_file.add(mi_exit);

        jMenuBar1.add(m_file);

        m_add.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_ADD"));

        mi_add_text.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_ADD_TEXT"));
        mi_add_text.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mi_add_textActionPerformed(evt);
            }
        });
        m_add.add(mi_add_text);

        mi_add_table.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_ADD_TABLE"));
        mi_add_table.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mi_add_tableActionPerformed(evt);
            }
        });
        m_add.add(mi_add_table);

        mi_add_image.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_ADD_IMAGE"));
        mi_add_image.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mi_add_imageActionPerformed(evt);
            }
        });
        m_add.add(mi_add_image);
        m_add.add(s_add_menu);

        mi_add_header_footer.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_ADD_HEADER_FOOTER"));
        mi_add_header_footer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mi_add_header_footerActionPerformed(evt);
            }
        });
        m_add.add(mi_add_header_footer);

        jMenuBar1.add(m_add);

        m_options.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_OPTIONS"));

        cbmi_show_icon_text.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_ICONS_TEXT"));
        cbmi_show_icon_text.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbmi_show_icon_textActionPerformed(evt);
            }
        });
        m_options.add(cbmi_show_icon_text);
        cbmi_show_icon_text.setSelected(true);

        m_icons.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_ICONS"));
        m_options.add(m_icons);

        m_themes.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_THEMES"));
        m_options.add(m_themes);

        m_language.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_LANGUAGE"));
        m_options.add(m_language);

        m_advanced.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_ADVANCED"));

        mi_free_unused_memory.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F6, 0));
        mi_free_unused_memory.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_FREE_UNUSED_MEMORY"));
        mi_free_unused_memory.setToolTipText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_TOOLTIP_FREE_UNUSED_MEMORY"));
        mi_free_unused_memory.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mi_free_unused_memoryActionPerformed(evt);
            }
        });
        m_advanced.add(mi_free_unused_memory);

        mi_open_logger.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_OPEN_LOGGER"));
        mi_open_logger.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mi_open_loggerActionPerformed(evt);
            }
        });
        m_advanced.add(mi_open_logger);

        m_options.add(m_advanced);

        jMenuBar1.add(m_options);

        m_help.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_HELP"));

        mi_feedback.setText(LocalizationManager.getCurrent_resource().getString("FEEDBACK_UI_TITLE"));
        mi_feedback.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mi_feedbackActionPerformed(evt);
            }
        });
        m_help.add(mi_feedback);

        mi_what_is_new.setText(LocalizationManager.getCurrent_resource().getString("WHAT_IS_NEW_TITLE"));
        mi_what_is_new.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mi_what_is_newActionPerformed(evt);
            }
        });
        m_help.add(mi_what_is_new);

        mi_about.setText(LocalizationManager.getCurrent_resource().getString("ABOUT_TITLE"));
        mi_about.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mi_aboutActionPerformed(evt);
            }
        });
        m_help.add(mi_about);

        jMenuBar1.add(m_help);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tb_toolbar, javax.swing.GroupLayout.DEFAULT_SIZE, 844, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(sp_split_pane, javax.swing.GroupLayout.DEFAULT_SIZE, 824, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(tb_toolbar, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sp_split_pane, javax.swing.GroupLayout.DEFAULT_SIZE, 488, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mi_exitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mi_exitActionPerformed
        Object[] option = {LocalizationManager.getCurrent_resource().getString("YES"), LocalizationManager.getCurrent_resource().getString("NO")};
        int opt = JOptionPane.showOptionDialog(rootPane, LocalizationManager.getCurrent_resource().getString("EXIT_CONFIRMATION"),
                LocalizationManager.getCurrent_resource().getString("EXIT"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, option, option[1]);

        if (opt == 0) {
            LoggerManager.getLogger().log(Level.INFO, "Program Terminated...{0}", project.jpdftools.toolkit.Toolkit.getLineSeparator());
            System.exit(0);
        } else {
            setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        }
}//GEN-LAST:event_mi_exitActionPerformed

    private void mi_free_unused_memoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mi_free_unused_memoryActionPerformed
        // call carbage collector to clean the memory
        System.gc();
        LoggerManager.getLogger().log(Level.INFO, "Garbage Collector called...");
}//GEN-LAST:event_mi_free_unused_memoryActionPerformed

    private void mi_what_is_newActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mi_what_is_newActionPerformed
        // make sure that the component is not visible
        if (WhatISNewScroll.IsComponentVisible() == false) {
            new WhatISNewScroll().setVisible(true);
        }
}//GEN-LAST:event_mi_what_is_newActionPerformed

    private void mi_aboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mi_aboutActionPerformed
        // make sure that the component is not visible
        if (ScrollAbout.IsComponentVisible() == false) {
            new ScrollAbout().setVisible(true);
        }
}//GEN-LAST:event_mi_aboutActionPerformed

    private void windowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_windowClosing
        mi_exitActionPerformed(null);
    }//GEN-LAST:event_windowClosing

    private void cbmi_show_icon_textActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbmi_show_icon_textActionPerformed
        if (cbmi_show_icon_text.isSelected() == true) {
            setIconsText(true);
        } else {
            setIconsText(false);
        }
    }//GEN-LAST:event_cbmi_show_icon_textActionPerformed

    private void bt_convertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_convertActionPerformed
        // make sure that the component is not visible
        if (PDFConverterUI.IsComponentVisible() == false) {
            new PDFConverterUI().setVisible(true);
        }
    }//GEN-LAST:event_bt_convertActionPerformed

    private void bt_split_fileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_split_fileActionPerformed
        // make sure that the component is not visible
        if (SplitterUI.IsComponentVisible() == false) {
            new SplitterUI().setVisible(true);
        }
    }//GEN-LAST:event_bt_split_fileActionPerformed

    private void bt_merge_filesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_merge_filesActionPerformed
        // make sure that the component is not visible
        if (PDFMergerUI.IsComponentVisible() == false) {
            new PDFMergerUI().setVisible(true);
        }
    }//GEN-LAST:event_bt_merge_filesActionPerformed

    private void bt_new_pdfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_new_pdfActionPerformed
        // check if the document is already empty
        if (p_right.getComponentCount() != 0) {
            // remove all components from right panel to trigger the start of the new document
            p_right.removeAll();
            // remove also all the components from the arraylist
            while (jpdf_data.isEmpty() == false) {
                jpdf_data.remove(0);
            }
            // immediately update the view of the components
            this.repaint();
        }
    }//GEN-LAST:event_bt_new_pdfActionPerformed

    private void bt_add_tableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_add_tableActionPerformed
        // add the popup menu to the add table button
        bt_add_table.setComponentPopupMenu(AddTablePopUpMenu.getInstance().getMenu());
        // show the popup menu
        AddTablePopUpMenu.getInstance().getMenu().show(MainMenu.getInstance(), bt_add_table.getLocationOnScreen().x + bt_add_table.getWidth(),
                bt_add_table.getLocationOnScreen().y);
    }//GEN-LAST:event_bt_add_tableActionPerformed

    private void bt_add_imageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_add_imageActionPerformed
    }//GEN-LAST:event_bt_add_imageActionPerformed

    private void bt_add_textActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_add_textActionPerformed
        // create a text object
        JPDFText text = new JPDFText();
        // add the object to the array of objects
        addObject(text);
        LoggerManager.getLogger().log(Level.INFO, "New text added. Component ID = {0}", text.getId());
    }//GEN-LAST:event_bt_add_textActionPerformed

    private void mi_file_page_setupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mi_file_page_setupActionPerformed
        // make sure that the panel is not already opened
        if (PageSetupUI.IsComponentVisible() == false) {
            new PageSetupUI().setVisible(true);
        }
    }//GEN-LAST:event_mi_file_page_setupActionPerformed

    private void mi_documnet_propertiesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mi_documnet_propertiesActionPerformed
        // make sure that the panel is not already opened
        if (DocumentInfoUI.IsComponentVisible() == false) {
            new DocumentInfoUI().setVisible(true);
        }
    }//GEN-LAST:event_mi_documnet_propertiesActionPerformed

    private void mi_add_textActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mi_add_textActionPerformed
        bt_add_textActionPerformed(evt);
    }//GEN-LAST:event_mi_add_textActionPerformed

    private void mi_add_tableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mi_add_tableActionPerformed
        // make sure that the component is not visible
        if (AddTablePanel.IsComponentVisible() == false) {
            new AddTablePanel().setVisible(true);
        }
    }//GEN-LAST:event_mi_add_tableActionPerformed

    private void mi_add_imageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mi_add_imageActionPerformed
        bt_add_imageActionPerformed(evt);
    }//GEN-LAST:event_mi_add_imageActionPerformed

    private void mi_add_header_footerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mi_add_header_footerActionPerformed
        // make sure that the panel is not already opened
        if (HeaderFooterUI.IsComponentVisible() == false) {
            new HeaderFooterUI().setVisible(true);
        }
    }//GEN-LAST:event_mi_add_header_footerActionPerformed

    private void mi_feedbackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mi_feedbackActionPerformed
        // make sure that the panel is not already opened
        if (FeedBackUI.IsComponentVisible() == false) {
            new FeedBackUI().setVisible(true);
        }
    }//GEN-LAST:event_mi_feedbackActionPerformed

    private void bt_merge_imagesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_merge_imagesActionPerformed
        // make sure that the panel is not already opened
        if (ImageMergerUI.IsComponentVisible() == false) {
            new ImageMergerUI().setVisible(true);
        }
    }//GEN-LAST:event_bt_merge_imagesActionPerformed

    private void mi_open_loggerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mi_open_loggerActionPerformed
        File log_file = new File("EventLog.txt");
        // check to see if the file already exists
        if (log_file.exists() == true) {
            try {
                // open the file
                Desktop.getDesktop().open(log_file);
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, LocalizationManager.getCurrent_resource().getString("FEEDBACK_UI_ERROR_WHILE_OPENING_LOG_FILE"),
                        LocalizationManager.getCurrent_resource().getString("ERROR"), 0);
                LoggerManager.getLogger().log(Level.SEVERE, "Error while opening log file. Message = {0}", project.jpdftools.toolkit.Toolkit.getStackTraceAsString(ex.getCause()));
            }
        } else {
            // file doesn't exist
            JOptionPane.showMessageDialog(null, LocalizationManager.getCurrent_resource().getString("FEEDBACK_UI_LOG_FILE_MISSING"),
                    LocalizationManager.getCurrent_resource().getString("MISSING_TITLE"), 0);
            LoggerManager.getLogger().log(Level.SEVERE, "Log file not found.");
        }
    }//GEN-LAST:event_mi_open_loggerActionPerformed

    /**
     * Show/Hide text of the buttons
     *
     * @param b
     */
    private void setIconsText(boolean b) {
        if (b == true) {
            bt_convert.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_CONVERT"));
            bt_load_file.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_LOAD_FILE"));
            bt_merge_files.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_MERGE_FILES"));
            bt_new_pdf.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_NEW_FILE"));
            bt_save_file.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_SAVE"));
            bt_split_file.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_SPLIT"));
            bt_merge_images.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_MERGE_IMAGE_FILES"));
            bt_add_text.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_ADD_TEXT"));
            bt_add_table.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_ADD_TABLE"));
            bt_add_image.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_ADD_IMAGE"));
            bt_export_pdf.setText(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_EXPORT_PDF"));
            LoggerManager.getLogger().log(Level.INFO, "Icons text shown.");
        } else {
            bt_convert.setText("");
            bt_load_file.setText("");
            bt_merge_files.setText("");
            bt_new_pdf.setText("");
            bt_save_file.setText("");
            bt_split_file.setText("");
            bt_merge_images.setText("");
            bt_add_text.setText("");
            bt_add_table.setText("");
            bt_add_image.setText("");
            bt_export_pdf.setText("");
            LoggerManager.getLogger().log(Level.INFO, "Icons text hidden.");
        }
    }

    /**
     * Returns the right panel of the MainMenu
     *
     * @return
     */
    public JPanel getP_right() {
        return p_right;
    }

    /**
     * Returns the right scroll pane of the MainMenu
     *
     * @return
     */
    public JScrollPane getScp_right() {
        return scp_right;
    }

    /**
     * Returns the array list holding all the JPDF objects created
     *
     * @return
     */
    public ArrayList<JPDF> getJpdf_data() {
        return jpdf_data;
    }

    /**
     * Returns the Convert button
     *
     * @return
     */
    public JButton getBt_convert() {
        return bt_convert;
    }

    /**
     * Returns the load button
     *
     * @return
     */
    public JButton getBt_load_file() {
        return bt_load_file;
    }

    /**
     * Returns the merge button
     *
     * @return
     */
    public JButton getBt_merge_files() {
        return bt_merge_files;
    }

    /**
     * Returns the new pdf button
     *
     * @return
     */
    public JButton getBt_new_pdf() {
        return bt_new_pdf;
    }

    /**
     * Returns the save button
     *
     * @return
     */
    public JButton getBt_save_file() {
        return bt_save_file;
    }

    /**
     * Returns the split button
     *
     * @return
     */
    public JButton getBt_split_file() {
        return bt_split_file;
    }

    /**
     * Returns the merge images button
     *
     * @return
     */
    public JButton getBt_merge_images() {
        return bt_merge_images;
    }

    /**
     * Returns the add image button
     *
     * @return
     */
    public JButton getBt_add_image() {
        return bt_add_image;
    }

    /**
     * Returns the add table button
     *
     * @return
     */
    public JButton getBt_add_table() {
        return bt_add_table;
    }

    /**
     * Returns the add text button
     *
     * @return
     */
    public JButton getBt_add_text() {
        return bt_add_text;
    }

    /**
     * Returns the export button
     *
     * @return
     */
    public JButton getBt_export_pdf() {
        return bt_export_pdf;
    }

    /**
     * Initialize the MainMenu object
     */
    public void intialize() {
        if (main_menu_instance != null) {
            // get the screen resolution
            Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
            // intialize the main menu
            // set the menu to the maximum size according to the system resolution
            main_menu_instance.setSize(screen.width, screen.height - 40);
            main_menu_instance.setAlwaysOnTop(false);
        }
    }

    /**
     * Add the JPDF object to the array of objects
     *
     * @param object
     */
    public void addObject(JPDF object) {
        // add the component in the JPDF array
        MainMenu.getInstance().getJpdf_data().add(object);
        // asign an id for the component
        object.setId(MainMenu.getInstance().getJpdf_data().size() - 1);
        // create the object UI
        object.createUI();
        // add the component to the right panel in the main menu
        p_right.add(object.getPanel());
        scp_right.setViewportView(p_right);
    }

    /**
     * Returns the MainMenu instance
     *
     * @return
     */
    public static MainMenu getInstance() {
        if (main_menu_instance == null) {
            main_menu_instance = new MainMenu();
        }
        return main_menu_instance;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_add_image;
    private javax.swing.JButton bt_add_table;
    private javax.swing.JButton bt_add_text;
    private javax.swing.JButton bt_convert;
    private javax.swing.JButton bt_export_pdf;
    private javax.swing.JButton bt_load_file;
    private javax.swing.JButton bt_merge_files;
    private javax.swing.JButton bt_merge_images;
    private javax.swing.JButton bt_new_pdf;
    private javax.swing.JButton bt_save_file;
    private javax.swing.JButton bt_split_file;
    private javax.swing.JCheckBoxMenuItem cbmi_show_icon_text;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JMenu m_add;
    private javax.swing.JMenu m_advanced;
    private javax.swing.JMenu m_file;
    private javax.swing.JMenu m_help;
    private javax.swing.JMenu m_icons;
    private javax.swing.JMenu m_language;
    private javax.swing.JMenu m_options;
    private javax.swing.JMenu m_themes;
    private javax.swing.JMenuItem mi_about;
    private javax.swing.JMenuItem mi_add_header_footer;
    private javax.swing.JMenuItem mi_add_image;
    private javax.swing.JMenuItem mi_add_table;
    private javax.swing.JMenuItem mi_add_text;
    private javax.swing.JMenuItem mi_documnet_properties;
    private javax.swing.JMenuItem mi_exit;
    private javax.swing.JMenuItem mi_feedback;
    private javax.swing.JMenuItem mi_file_page_setup;
    private javax.swing.JMenuItem mi_free_unused_memory;
    private javax.swing.JMenuItem mi_open_logger;
    private javax.swing.JMenuItem mi_what_is_new;
    private javax.swing.JPanel p_right;
    private javax.swing.JPanel p_sidebar;
    private javax.swing.JPopupMenu.Separator s_add_menu;
    private javax.swing.JPopupMenu.Separator s_file_menu;
    private javax.swing.JToolBar.Separator s_toolbar;
    private javax.swing.JScrollPane scp_left;
    private javax.swing.JScrollPane scp_right;
    private javax.swing.JSplitPane sp_split_pane;
    private javax.swing.JToolBar tb_side_toolbar;
    private javax.swing.JToolBar tb_toolbar;
    // End of variables declaration//GEN-END:variables
}
